function Validate(id,order){
    this.id = id;
    this.order = order;
    var that;
}

Validate.prototype = {
    "formObj":'',
    "element":[],
    "data":[],
    "isContinue":true,
    "regexp":{
        isempty:function(s){if(s.length==0){return true}else{return false}},
        mobile:function(s) { return !(/^1[0-9]{10}$/.test(s)); },
    },
    init:function() {
        that = this;
        that.isContinue = true;
        that.formObj = $("#" + that.id);
        that.formObj.find("input[type=text]").each(function() {
            that.element.push($(this).attr("data-order"));
        });
        that.formObj.find("input[type=password]").each(function() {
            that.element.push($(this).attr("data-order"));
        });
        that.formObj.find("input[type=hidden]").each(function() {
            that.element.push($(this).attr("data-order"));
        });
        that.formObj.find("select").each(function() {
            that.element.push($(this).attr("data-order"));
        });
        if(that.order){
            that.element.sort();
        }
        var flag = that.checkIn();
        return {
            "flag":flag,
            "data":that.data
        };
    },
    _switch:function(type,value) {
        switch(type){
            case "isempty":
                return that.regexp.isempty(value);
                break;
            case "istel":
                return that.regexp.mobile(value);
                break;
            default:
                return true;
                break;
        }
    },
    checkIn:function() {
        var i;
        var id;
        var obj;
        var type;
        var flag;
        var value;
        var notice;
        that.data = [];
        //console.log(that.formObj);
        var len = that.element.length;
        for (i = 0; i < len; i++) {
            obj = that.formObj.find("[data-order="+that.element[i]+"]");
            id = that.formObj.find("[data-order="+that.element[i]+"]").attr("id");
            
            type = obj.attr("data-type");
            value = $.trim(obj.val());
            notice = obj.attr("data-notice");
            flag = that._switch(type,value);
            if(flag) {
                that.isContinue = false;
                obj.siblings(".err-tips").html(notice);
                obj.siblings(".err-tips").css("color","#ff4343");
            }else{
                obj.siblings(".err-tips").html('');
                obj.siblings(".err-tips").css("color","inherit");
            }
            that.data[id] = value;
        }
        if(!that.isContinue) {
            return false;
        }else{
            return true;
        }
    }
}

/*
if (!Array.prototype.forEach) {  
    Array.prototype.forEach = function(callback, thisArg) {  
        var T, k;  
        if (this == null) {  
            throw new TypeError(" this is null or not defined");  
        }  
        var O = Object(this);  
        var len = O.length >>> 0; // Hack to convert O.length to a UInt32  
        if ({}.toString.call(callback) != "[object Function]") {  
            throw new TypeError(callback + " is not a function");  
        }  
        if (thisArg) {  
            T = thisArg;  
        }  
        k = 0;  
        while (k < len) {  
            var kValue;  
            if (k in O) {  
                kValue = O[k];  
                callback.call(T, kValue, k, O);  
            }  
            k++;  
        }  
    };  
}
*/ 